var express = require("express");
var app = express();
var db = require("./model/db.js")
var session = require("express-session");

app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true,
}))

app.set("view engine","ejs");

app.get("/",function(res,res){
    
});

app.get("/login",function(req,res){
    res.render("login");
});

app.get("/checklogin",function(req,res){
    var Tusername = req.query.username;
    var Tpassword = req.query.password;
    db.find("User",{"username":Tusername},function(err,result){
        if(result.length == 0){
            res.send("没有此登录用户");
            return;
        }
        var Pass = result[0].password;      // 数据库的用户
        if(Pass == Tpassword){
            req.session.login = "1";
            req.session.username = result[0].username;
            res.send("成功登录，你是" +result[0].username)
        }else{
            res.send("密码错误");
        }
    });
});

app.listen(3000)